﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ScrumLogin
{
   
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
       
        public Window1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {            
            SqlConnection myConnection = new SqlConnection( @"Server=user-ПК\sql;Database=ScrumMagic;Integrated Security=yes"/*ConfigurationManager.AppSettings["ConnectionString"]*/);
            
            myConnection.Open();
            /*SqlCommand myCommand = new SqlCommand("INSERT INTO Users (Id,Login,Password,FirstName,MiddleName,LastName,EMail)"+ 
            "values(1,'amirka','parol1','amir','romashkin','sergeevich','amirin@mail.ru');", myConnection);
            */
            /*SqlCommand myCommand = new SqlCommand("INSERT INTO Users (Id,Login,Password,FirstName,MiddleName,LastName,EMail)" +
            "values(2,'sergei','parol2','sergei','ivanov','sergeevich','sergin@mail.ru');", myConnection);          
            */

            
            SqlDataReader myReader = null;
            SqlCommand myCommand = new SqlCommand("SELECT Password FROM [User] where login='"+textBox1.Text+"';", myConnection);
            myReader = myCommand.ExecuteReader();
            
            bool bo = false;
            short i=0;
            while (myReader.Read())
            {
                i++;
                if (myReader["Password"].ToString() == passwordBox1.Password)
                { 
                    bo = true; };
            };
      
            myConnection.Close();

            if (bo) 
            { 
                MessageBox.Show("You are in!"); 
            } 
            else  
                if ( (!bo) & (i!=0) )  
                { 
                    MessageBox.Show("Your password is incorrect. Please try again."); 
                } 
                else 
                {
                    MessageBox.Show(@"Your login is incorrect or you are not available to enter.
Please try again.");
                };           
        }
    }
}
